package com.stock.domain.vo.response;

import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

@ApiModel(description = "分页结果")
@Data
public class PageResponse<T> implements Serializable {
    /*
     * 总行数
     */
    @ApiModelProperty("总行数")
    private Long totalRows;

    /*
     * 总页数
     */
    @ApiModelProperty("总页数")
    private Long totalPages;

    /*
     * 当前页
     */
    @ApiModelProperty("当前页")
    private Integer pageNum;

    /*
     * 每页大小
     */
    @ApiModelProperty("每页大小")
    private Integer pageSize;

    /*
     * 当前页大小
     */
    @ApiModelProperty("当前页大小")
    private Integer size;

    /*
     * 结果集合
     */
    @ApiModelProperty("结果集合")
    private List<T> rows;

    /**
     * 分页数据组装
     *
     * @param pageInfo
     * @return
     */
    public PageResponse(PageInfo<T> pageInfo) {
        totalRows = pageInfo.getTotal();
        totalPages = (long) pageInfo.getPages();
        pageNum = pageInfo.getPageNum();
        pageSize = pageInfo.getPageSize();
        size = pageInfo.getSize();
        rows = pageInfo.getList();
    }
}
